From f1d39feaf9cb0ad2f7ff5b88a9019903491ff9a9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 7 Sep 2014 11:26:07 -0700 Subject: [PATCH] Don't run cargo as root during `make install` This rejiggers the dependencies for `make install` to only copy files into the destination, never assemble anything. This adds a hard requirement that `make` is executed before `make install`. Closes #519 --- Makefile.in | 19 ++++++++++++++----- src/etc/install.sh | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Makefile.in b/Makefile.in index b1303b1a5..47f7656fc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -115,7 +115,9 @@ distcheck-$(1): dist-$(1) $$(DISTDIR_$(1))/$$(PKG_NAME)-$(1).tar.gz: $$(PKGDIR_$(1))/lib/cargo/manifest.in tar -czvf $$@ -C $$(@D) $$(PKG_NAME)-$(1) -$$(PKGDIR_$(1))/lib/cargo/manifest.in: all +$$(PKGDIR_$(1))/lib/cargo/manifest.in: + @[ -f $$(TARGET_$(1))/cargo$$(X) ] || echo 'Please run `make` first' + @[ -f $$(TARGET_$(1))/cargo$$(X) ] rm -rf $$(PKGDIR_$(1)) mkdir -p $$(PKGDIR_$(1))/bin $$(PKGDIR_$(1))/lib/cargo cp $$(TARGET_$(1))/cargo$$(X) $$(PKGDIR_$(1))/bin @@ -128,16 +130,23 @@ $$(PKGDIR_$(1))/lib/cargo/manifest.in: all mv $$(DISTDIR_$(1))/manifest-$$(PKG_NAME).in \ $$(PKGDIR_$(1))/lib/cargo/manifest.in -install-$(1): $$(PKGDIR_$(1))/lib/cargo/manifest.in +ifeq (root user, $$(USER) $$(patsubst %,user,$$(SUDO_USER))) +prepare-manifest-$(1): + @sudo -u "$$$$SUDO_USER" $$(MAKE) prepare-manifest-$(1) +else +prepare-manifest-$(1): $$(PKGDIR_$(1))/lib/cargo/manifest.in +endif + +install-$(1): prepare-manifest-$(1) $$(PKGDIR_$(1))/install.sh \ --prefix="$$(CFG_PREFIX)" \ --destdir="$$(DESTDIR)/" $$(MAYBE_DISABLE_VERIFY) endef $(foreach target,$(CFG_TARGET),$(eval $(call DO_DIST_TARGET,$(target)))) -dist: $(CARGO) $(foreach target,$(CFG_TARGET),dist-$(target)) -distcheck: $(CARGO) $(foreach target,$(CFG_TARGET),distcheck-$(target)) -install: $(CARGO) $(foreach target,$(CFG_TARGET),install-$(target)) +dist: $(foreach target,$(CFG_TARGET),dist-$(target)) +distcheck: $(foreach target,$(CFG_TARGET),distcheck-$(target)) +install: $(foreach target,$(CFG_TARGET),install-$(target)) # Setup phony tasks .PHONY: all clean test test-unit style diff --git a/src/etc/install.sh b/src/etc/install.sh index 5eeb316f9..5d913c75a 100755 --- a/src/etc/install.sh +++ b/src/etc/install.sh @@ -305,7 +305,7 @@ then if [ -z "${CFG_UNINSTALL}" ] then msg "verifying platform can run binaries" - "${CFG_SRC_DIR}/bin/cargo" -V > /dev/null + "${CFG_SRC_DIR}/bin/cargo" -V 2> /dev/null if [ $? -ne 0 ] then err "can't execute rustc binary on this platform" @@ -448,7 +448,7 @@ done < "${CFG_SRC_DIR}/${CFG_LIBDIR_RELATIVE}/cargo/manifest.in" if [ -z "${CFG_DISABLE_VERIFY}" ] then msg "verifying installed binaries are executable" - "${CFG_DESTDIR}${CFG_PREFIX}/bin/cargo" -V > /dev/null + "${CFG_DESTDIR}${CFG_PREFIX}/bin/cargo" -V 2> /dev/null if [ $? -ne 0 ] then ERR="can't execute installed rustc binary. " -- 2.30.2